<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of BMP
 *
 * @author 梅小春 476984957@qq.com
 */
class BMP {

    public static function save($palette, $bmpData, $paletteLength, $width, $height, $bit, $filename) {
        $size_quad = strlen($palette);
        $size_data = strlen($bmpData);
        // 位图文件头
        $fileHeader = "BM" . pack("V3", 54 + $size_quad + $size_data, 0, 54 + $size_quad);
        // 位图信息头
        $infoHeader = pack("V3v2V*", 0x28, $width, $height, 1, $bit, 0, $size_data, 0, 0, $paletteLength, 0);
        // 写入文件
        if ($filename != '') {
            $fp = fopen($filename, "wb");
            fwrite($fp, $fileHeader);
            fwrite($fp, $infoHeader);
            fwrite($fp, $palette);
            fwrite($fp, $bmpData);
            fclose($fp);
        }
    }

}
